home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / misc / aterminfo.lha / lib_tputs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  1.8 KB  |  101 lines

  1.  
  2. /* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for   *
  3. *  details. If they are missing then this copy is in violation of    *
  4. *  the copyright conditions.                                        */
  5.  
  6. /*
  7.  *    tputs.c
  8.  *
  9.  */
  10.  
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include "term.h"
  14.  
  15. int tputs(string, affcnt, outc)
  16. char    *string;
  17. int    affcnt;
  18. int    (*outc)();
  19. {
  20. float    number;
  21. #ifndef _AMIGA
  22. int    baud = baudrate();
  23. #else
  24. int    baud = 9600;
  25. #endif
  26. char    null = '\0';
  27. int    i;
  28.  
  29. #ifdef TRACE
  30.     if (_tracing)
  31.         _tracef("tputs(\"%s\", %d, %o) called", string, affcnt, outc);
  32. #endif
  33.  
  34.     if (string == NULL)
  35.         return ERR;
  36.     if (pad_char)
  37.         null = pad_char[0];
  38.  
  39.     while (*string) {
  40.         if (*string != '$')
  41.             (*outc)(*string);
  42.         else {
  43.             string++;
  44.             if (*string != '<') {
  45.                 (*outc)('$');
  46.                 (*outc)(*string);
  47.             } else {
  48.  
  49.                 number = 0;
  50.                 string++;
  51.  
  52.                 if ((!isdigit(*string) && *string != '.') || !strchr(string, '>')) {
  53.                     (*outc)('$');
  54.                     (*outc)('<');
  55.                     continue;
  56.                 }
  57.                 while (isdigit(*string)) {
  58.                     number = number * 10 + *string - '0';
  59.                     string++;
  60.                 }
  61.  
  62.                 if (*string == '.') {
  63.                     string++;
  64.                     if (isdigit(*string)) {
  65.                         number += (float) (*string - '0') / 10.;
  66.                         string++;
  67.                     }
  68.                 }
  69.  
  70.                 if (*string == '*') {
  71.                     number *= affcnt;
  72.                     string++;
  73.                 }
  74.  
  75.                 if (padding_baud_rate  &&  baud >= padding_baud_rate && !xon_xoff) {
  76.                     number = ((baud / 10.) * number) / 1000.;
  77.  
  78.                     for (i=0; i < number; i++)
  79.                         (*outc)(null);
  80.                 }
  81.  
  82.             } /* endelse (*string == '<') */
  83.         } /* endelse (*string == '$') */
  84.  
  85.         if (*string == '\0')
  86.             break;
  87.  
  88.         string++;
  89.     }
  90.     return OK;
  91. }
  92.  
  93. int putp(char *string)
  94. {
  95. #ifdef TRACE
  96.     if (_tracing)
  97.         _tracef("putp(%s) called", string);
  98. #endif
  99.     return(tputs(string, 1, putchar));
  100. }
  101.